﻿<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>用户-列表</title>

    <link rel="shortcut icon" href="favicon.ico">
	<link href="css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="css/font-awesome.min.css?v=4.4.0" rel="stylesheet">

    <!-- Data Tables -->
    <link href="css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
    <link href="js/plugins/layui/css/layui.css" rel="stylesheet">
    <link href="css/animate.min.css" rel="stylesheet">
    <link href="css/plugins/toastr/toastr.min.css" rel="stylesheet">
    <link href="css/style.min.css?v=4.0.0" rel="stylesheet" />

</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title"  style="height:72px;">
                        <div class="ibox-tools">

                            <a class="collapse-link" href="javascript:location.href=location.href;">
                                <i class="fa fa-refresh"></i>
                            </a>
                        </div>
                        <h5>基本 <small>分类/查找</small></h5>
						<div class="col-sm-12">
						<div class="col-sm-6">
							<div class="col-sm-5">
							<div class="input-group input-group-sm ">
								<input name="usernameOrNick" type="text" class="form-control" placeholder="昵称、账号或邮箱">
								<span class="input-group-btn"> <button id="searchSysUser" type="button" class="btn btn-primary">搜索
								</button> </span>
							</div>
							</div>
						</div>
						<div class="col-sm-6 text-right">
							<button type="button" id="showAddUser" class="btn btn-sm btn-success add">新增</button>
						</div>
						</div>
                    </div>
                    <div class="ibox-content">

                        <table id="layTab" class="table table-striped table-bordered table-hover dataTables-example">
                            <thead>
                                <tr>
                                    <th>用户昵称</th>
                                    <th>账号</th>
									<th>邮箱</th>
									<th>角色</th>
                                    <th>状态</th>
                                    <th>创建人</th>
                                    <th>创建时间</th>
									<th width="20%">操作</th>
                                </tr>
                            </thead>
                            <tbody>
                            </tbody>
							<tfoot>

							</tfoot>
                        </table>

                    </div>
                </div>
            </div>
        </div>

    </div>
    <script src="js/jquery.min.js?v=2.1.4"></script>
    <script src="js/bootstrap.min.js?v=3.3.5"></script>
	<script src="js/plugins/toastr/toastr.min.js"></script>
	<script src="js/plugins/layui/layui.js"></script>
	<script src="js/custom/layTool.js"></script>
    <script type="text/javascript" src="js/custom/app.js" charset="UTF-8"></script>
    <script type="text/javascript" src="js/custom/tools.js" charset="UTF-8"></script>
    <script>
	var pageSize = 10;
	var pageNumber = 1;
	function searchSysUser(pageNumber ,pageSize,usernameOrNick){
		var url = 'sysUser/queryAllSysUserMainInfoByPage';
		jQuery.ajax({
			url:domain + url,
			type:"get",
			data:{"usernameOrNick":usernameOrNick,"page":pageNumber,"pageSize":pageSize},
			crossDomain:true,
			xhrFields:{
				withCredentials:true
			},
			success:function (data) {
				if(data.status == 200){
					var totalPage = data.data.total;//总页数
					pageNumber = data.data.page;//当前页
					var totalRow = data.data.records;//总条数

					//拼凑html
					combHTML(data.data.rows);
					var arr = [usernameOrNick];
				   //分页
					LayPage('layTab',totalPage,totalRow,pageNumber ,pageSize,"searchSysUser",arr);
				}else{
					top.toastr.warning(data.msg);
				}
			},
			error:function(data) {
				top.toastr.error("查询列表失败，请检查网络");
			}
		})

	}

	function combHTML(data){
		var htmls = new Array();
		for (var i=0;i<data.length;i++){
			htmls.push('<tr class="gradeU">');
			htmls.push('		<td>'+ data[i].nickName +'</td>');
			htmls.push('		<td>'+ data[i].username +'</td>');
			htmls.push('		<td>'+ data[i].mail +'</td>');
			htmls.push('		<td data-code="'+ data[i].roleCode +'">'+ data[i].roleName +'</td>');
			htmls.push('		<td>'+ getStatus(data[i].status) +'</td>');
			htmls.push('		<td>'+ data[i].createBy +'</td>');
			htmls.push('		<td>'+ data[i].createTime +'</td>');
			htmls.push('		<td><button type="button" data-code="'+ data[i].username
									+'" class="btn btn-xs btn-outline btn-info showUserDetail search_detail">用户详情</button>');
			htmls.push('		<button type="button" data-code="'+ data[i].username
									+'" class="btn btn-xs btn-outline btn-warning showUpdateUserRoleStatus update_role_status">切换角色或状态</button>');
			htmls.push('		<button type="button" data-code="'+ data[i].username
									+'" class="btn btn-xs btn-outline btn-danger showDeleteUser delete">删除</button></td>');
			htmls.push('</tr>');

		}
		$("#layTab tbody").html(htmls.join(''));


		//切换角色或状态
		$(".showUpdateUserRoleStatus").on("click",function(){
			var username = $(this).data("code");
			layerOpen('切换角色或状态','user-edit.html?username='+encodeURI(username),'600','330');
		});

		//查看用户详情
		$(".showUserDetail").on("click",function(){
			var username = $(this).data("code");
			//layerOpen('用户详情','user-detail-edit.html?username='+encodeURI(username),'600','530');
			layui.use(['layer'], function(){
				var layer = layui.layer;
				layer.open({
					type: 1,
					title: false, //不显示标题
					skin: 'layui-layer-rim', //加上边框
					area: ['700px', '300px'], //宽高
					content: $("#user_profile"),
					success:function(){
						showUserBasicInfo(username);
					}
				});
			});
		});

		//删除用户
		$(".showDeleteUser").on("click",function(){
			var username = $(this).data("code");
			deleteSysUser(username);
		});

	}

	//查询用户基本信息详情
	function showUserBasicInfo(username){
		var url = 'sysUser/getSysUserAndRoleByUsername';
		jQuery.ajax({
			url:domain + url,
			type:"get",
			data:{"username":username},
			crossDomain:true,
			xhrFields:{
				withCredentials:true
			},
			success:function (data) {
				if(data.status == 200){
					combUserProfileHTML(data.data);
				}else{
					top.toastr.warning(data.msg);
				}
			},
			error:function(data) {
				top.toastr.error("查询列表失败，请检查网络");
			}
		})
	}

	function combUserProfileHTML(data){
		$("#profile_username").html(data.username);
		$("#profile_nickName").html(data.nickName);

		$("#profile_status").removeClass("label-primary").removeClass("label-danger");
		if(data.status == "ON"){
			$("#profile_status").html("已启用");
			$("#profile_status").addClass("label-primary");
		}else if(data.status == "OFF"){
			$("#profile_status").html("已禁用");
			$("#profile_status").addClass("label-danger");
		}else{
			$("#profile_status").html(data.status);
		}
		$("#profile_note").html(data.note);
		$("#profile_roleName").html(data.roleName);
		$("#profile_mail").html(data.mail);
		$("#profile_createTime").html(data.createTime);
		$("#profile_createBy").html(data.createBy);
		$("#profile_updateTime").html(data.updateTime);
		$("#profile_updateBy").html(data.updateBy);
		$("#profile_source").html(data.source);
		$("#profile_signature").html(data.signature);
		$("#profile_profilePhoto").attr("src",domain+data.profilePhoto);
		$("#profile_position").html(data.position);
		$("#profile_birthday").html(data.birthday);
	}

	function deleteSysUser(username){
		layui.use(['layer'], function(){
			var layer = layui.layer;
			layer.confirm('确定删除？', {
				title:false,
				icon:7,
				btn: ["确定",'取消'] //按钮
			}, function(){
				var url = 'sysUser/deleteSysUserByUsername';
				jQuery.ajax({
					url:domain + url,
					type:"post",
					data:{"username":username},
					crossDomain:true,
					xhrFields:{
						withCredentials:true
					},
					success:function (data) {
						if(data.status == 200){
							top.toastr.success("操作成功");
							searchSysUser(pageNumber,pageSize,"");
							layer.close(layer.index);
						}else{
							top.toastr.warning(data.msg);
						}
					},
					error:function(data) {
						top.toastr.error("查询列表失败，请检查网络");
					}
				})
			});
		});
	}

	$(function(){
		searchSysUser(pageNumber,pageSize,"");
		$("#searchSysUser").on("click",function(){
			searchSysUser(pageNumber,pageSize,$("input[name=usernameOrNick]").val());
		})
		document.onkeydown = function(event){
			event=document.all?window.event:event;
			 if((event.keyCode || event.which)==13){
				searchSysUser(pageNumber,pageSize,$("input[name=usernameOrNick]").val());
			}
		}

		//新增用户
		$("#showAddUser").on("click",function(){
			layerOpen('新增用户(默认密码：123456)','user-add.html','600','380');
		});
	})

	//


	</script>

	<script>	//=======   页面权限显示   ======//
	//当前菜单代码 (每个页面不一样，需要配置)
		var s_menuCode = "userRun";
	//所有可用权限
		var roleAuth = app.permission(s_menuCode);
	//当前菜单所有可用权限（排除被禁用的按钮）
		var menuAuth = app.menuButtonByOn(s_menuCode);

		drawBtn(roleAuth,menuAuth);
	</script>


</body>
<!--- 个人资料 -->
	<style>
		.dl-horizontal dt{width:70px;padding-bottom:10px;}
		.dl-horizontal dd{margin-left:85px;}
		#profile_status{width: 50px;line-height: 20px;height: 24px;}
		#user_profile .ibox-title{margin-bottom:0;}
	</style>
	<div id="user_profile" style="display:none;" class="ibox">
		<div class="ibox-title">
			<p id="profile_status" class="label pull-right"></p>
			<h3 id="profile_nickName"></h2>
		</div>
		<div class="ibox-content" style="padding-left:5px;">
			<div class="row" >
				<div class="col-sm-3" style="padding:0 15px 0 30px;">
					<div class="text-center">
						<img id="profile_profilePhoto" alt="image" class="img-circle m-t-xs img-responsive" src="img/a1.jpg">
						<div id="profile_roleName" class="m-t-xs font-bold"></div>
					</div>
				</div>
				<div class="col-sm-4" style="padding-left:0;">
					<dl class="dl-horizontal">
						<dt>账号：</dt><dd id="profile_username"></dd>
						<dt>邮箱：</dt><dd id="profile_mail"></dd>
						<dt>创建人：</dt><dd id="profile_createBy"></dd>
						<dt>创建时间：</dt><dd id="profile_createTime"></dd>
						<dt>来源：</dt><dd id="profile_source"></dd>
						<dt>签名：</dt><dd id="profile_signature"></dd>
					</dl>
				</div>
				<div class="col-sm-4" style="padding:0;">
					<dl class="dl-horizontal">
						<dt>生日：</dt><dd id="profile_birthday"></dd>
						<dt>职位：</dt><dd id="profile_position"></dd>
						<dt>更新人：</dt><dd id="profile_updateBy"></dd>
						<dt>更新时间：</dt><dd id="profile_updateTime"></dd>
						<dt>备注：</dt><dd id="profile_note"></dd>
					</dl>
				</div>
			</div>
		</div>
	</div>
</html>
